package Collection;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Iterator;

public class CollectonDemo4 {
    public static void main(String[] args) {
      ArrayList<Student> list = new ArrayList<>();
        Student student1 = new Student("张三",21);
        Student student2 = new Student("李四",18);
        Student student3 = new Student("王五",33);
        list.add(student1);
        list.add(student2);
        list.add(student3);
        for (Student student : list) {
            System.out.println(student);
        }
        System.out.println("--------------");
        Iterator<Student> it = list.iterator();
        while (it.hasNext()){
            Student s=it.next();
            System.out.println(s);
        }

    }
}
class Student{
    private String name;
    private int age;

    public Student() {
    }

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}